//邮箱
function vrf_email(val){
	return vrf(/^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/,val);
}
//邮编
function vrf_postcode(val){
	return vrf(/^\d{6}$/,val);
}
//手机
function vrf_phone(val){
	return vrf(/^1\d{10}$/,val);
}
//固话：XXX-XXXXXXX-XXX
function vrf_tel(val){
	//return vrf(/^((0\d{2,3})-)(\d{7,8})(-(\d{3,}))?$/,val);
	return vrf(/^((0\d{2,3})-)(\d{7,8})(-(\d{1,4}))?$/,val);
}
//固话或手机
function vrf_telPhone(val){
	//return vrf(/(^(0[0-9]{2,3}\-)?([2-9][0-9]{6,7})+(\-[0-9]{1,4})?$)|(^((\(\d{3}\))|(\d{3}\-))?(1[358]\d{9})$)/,val);
	return vrf(/(^(0[0-9]{2,3}\-)?([0-9]{7,8})+(\-[0-9]{1,4})?$)|^1\d{10}$/,val);
}
//6-16位字母数字密码,可以用@!#$%^&*.~特殊字符
function vrf_psw(val){
	return vrf(/^[\@A-Za-z0-9\!\#\$\%\^\&\*\.\~]{6,16}$/,val);
}
//6-16位字母数字密码,不可以用@!#$%^&*.~特殊字符
function vrf_psw_noSpecial(val){
  return vrf(/^[A-Za-z0-9]{6,16}$/,val);
}
//纯数字
function vrf_int(val){
	return vrf(/^[0-9]*$/,val);
}
//纯数字或字母
function vrf_intLetter(val){
	return vrf(/^[A-Za-z0-9]*$/,val);
}
//用户名:(2-20位)中文\大小写字母\下划线\数字\中划线
function vrf_name(val){
	//return vrf(/^[0-9a-zA-Z\xa0-\xff_-]{2,15}$/,val);
	return vrf(/^[0-9a-zA-Z\u4e00-\u9fa5]{1}[a-zA-Z0-9_\u4e00-\u9fa5]{1,19}$/,val);
}


function vrf(vrf1,val){
	//if(val==null) return false;
	if(vrf1.test(val))
	return 1; 
	else
	return 0;
}
// 判断输入是否是有效的长日期格式 - "YYYY-MM-DD HH:MM:SS" || "YYYY/MM/DD HH:MM:SS"
function vrf_datetime(datetime,type)
{
if(type=='-')
var result=datetime.match(/^(\d{4})(-)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
else if(type=='/')
var result=datetime.match(/^(\d{4})(\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
else
var result=datetime.match(/^(\d{4})(-|\/)(\d{1,2})\2(\d{1,2}) (\d{1,2}):(\d{1,2}):(\d{1,2})$/);
if(result==null) return false;
var d= new Date(result[1], result[3]-1, result[4], result[5], result[6], result[7]);
return (d.getFullYear()==result[1]&&(d.getMonth()+1)==result[3]&&d.getDate()==result[4]&&d.getHours()==result[5]&&d.getMinutes()==result[6]&&d.getSeconds()==result[7]);
} 


/**  
 * 通过身份证判断是男是女  
 * @param idCard 15/18位身份证号码   
 * @return 'female'-女0、'male'-男1  
 */ 
function maleOrFemalByIdCard(idCard){   
    idCard = trim(idCard.replace(/ /g, ""));// 对身份证号码做处理。包括字符间有空格。   
    if(idCard.length==15){   
        if(idCard.substring(14,15)%2==0){   
            return '0';   
        }else{   
            return '1';   
        }   
    }else if(idCard.length ==18){   
        if(idCard.substring(14,17)%2==0){   
            return '0';   
        }else{   
            return '1';   
        }   
    }else{   
        return null;   
    }     
}


/*
功能：验证身份证号码是否有效
提 示信息：未输入或输入身份证号不正确！
使用：validateIdCard(obj)
返回：0,1,2,3
*/
function validateIdCard(obj) {
    var aCity={11:"北京",12:"天津",13:"河北",14:"山西",15:"内蒙古",21:"辽宁",22:"吉林",23:"黑龙 江",31:"上海",32:"江苏",33:"浙江",34:"安徽",35:"福建",36:"江西",37:"山东",41:"河南",42:"湖 北",43:"湖南",44:"广东",45:"广西",46:"海南",50:"重庆",51:"四川",52:"贵州",53:"云南",54:"西 藏",61:"陕西",62:"甘肃",63:"青海",64:"宁夏",65:"新疆",71:"台湾",81:"香港",82:"澳门",91:"国 外"};
    var iSum = 0;
    //var info = "";
    var strIDno = obj;
    // var idCardLength = strIDno.length;
    if (!/^\d{17}(\d|x)$/i.test(strIDno) && !/^\d{15}$/i.test(strIDno))
        return 1; //非法身份证号

    if (aCity[parseInt(strIDno.substr(0, 2))] == null)
        return 2; // 非法地区
    // 判断是否大于2078年，小于1900年
    var year = strIDno.substring(6, 10);
    if (year < 1900 || year > 2014)
        return 3; //非法生日

    //18位身份证处理

    //在后面的运算中x相当于数字10,所以转换成a
    strIDno = strIDno.replace(/x$/i, "a");

    sBirthday = strIDno.substr(6, 4) + "-" + Number(strIDno.substr(10, 2)) + "-" + Number(strIDno.substr(12, 2));
    var d = new Date(sBirthday.replace(/-/g, "/"))
    if (sBirthday != (d.getFullYear() + "-" + (d.getMonth() + 1) + "-" + d.getDate()))
        return 3; //非法生日
    // 身份证编码规范验证
    for (var i = 17; i >= 0; i--)
        iSum += (Math.pow(2, i) % 11) * parseInt(strIDno.charAt(17 - i), 11);
    if (iSum % 11 != 1)
        return 1; // 非法身份证号

    // 判断是否屏蔽身份证
    var words = new Array();
    words = new Array("11111119111111111", "12121219121212121");

    for (var k = 0; k < words.length; k++) {
        if (strIDno.indexOf(words[k]) != -1) {
            return 1;
        }
    }

    return 0;
}
